package com.htl.io.字节流;

import java.io.File;
import java.io.IOException;

public class File__test {
    public static void main(String[] args) {
        File file1 = new File("D:\\Project\\IDEA_project\\java_note\\src\\com\\htl\\io\\test1.txt");
        System.out.println(file1);
        System.out.println("文件名："+file1.getName());
        System.out.println("文件长度：" + file1.length());
        System.out.println("文件路劲：" + file1.getPath());
        System.out.println("文件的patent：" + file1.getParent());
        System.out.println("文件的parentFile：" + file1.getParentFile());
        System.out.println("=======================================================================");


        File parentField = file1.getParentFile();
        if (parentField.isDirectory()) {
            System.out.println("parentField是一个文件夹");
        }
        System.out.println("-----------------------------------------------------------------------");


        File file2 = new File("D:\\Project\\IDEA_project\\java_note" +
                "\\src\\com\\htl\\io\\test2.txt");
        System.out.println(file2.exists());
        if (!file2.exists()) {
            try {
                // 创建新文件
                System.out.println(file2.createNewFile());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        System.out.println("-----------------------------------------------------------------------");


        File file3 = new File("D:\\Project\\IDEA_project\\java_note" +
                "\\src\\com\\htl\\io\\test2.txt");
        File file4 = new File("D:\\Project\\IDEA_project\\java_note" +
                "\\src\\com\\htl\\io\\test4.txt");
        // file3的名字改成file4的名字
        System.out.println(file3.renameTo(file4));
        // 删除file4
        System.out.println(file4.delete());
    }
}
